package com.Smart.smartscals.Fragment;

import javax.crypto.Mac;

import com.Smart.smartscals.Activity.ActivityGuide;
import com.Smart.smartscals.Activity.R;
import com.Smart.smartscals.Adapter.ArrayWheelAdapter;
import com.Smart.smartscals.CustomView.CustomScrovieView;
import com.Smart.smartscals.CustomView.CustomWheelView;
import com.Smart.smartscals.Entity.EntityConversionTime;
import com.Smart.smartscals.Entity.EntityWheelView;
import com.Smart.smartscals.Utils.Const;
import com.Smart.smartscals.Utils.Tools;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

public class FragmentGudeAge extends BaseFragment {

	private CustomScrovieView mCustomScrovieView;
	private EntityWheelView entityWheelView;
	private int mAge;
	

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		initView();
		initParam();
		setListener();
	}

	private void initParam() {
		
		mActivityGuide = (ActivityGuide) this.getActivity();
		ArrayWheelAdapter<String> arrayWheelAdapter = new ArrayWheelAdapter<String>(
				new String[] { "5", "6", "7", "8", "9", "10", "11", "12", "13",
						"14", "15", "16", "17", "18", "19", "20", "21", "22",
						"23", "24", "25", "26", "27", "28", "29", "30", "31",
						"32", "33", "34", "35", "36", "37", "38", "39", "40",
						"41", "42", "43", "44", "45", "46", "47", "48", "49",
						"50", "51", "52", "53", "54", "55", "56", "57", "58",
						"59", "60", "61", "62", "63", "64", "65", "66", "67",
						"68", "69", "70", "71", "72", "73", "74", "75", "76",
						"77", "78", "79", "80", "81", "82", "83", "84", "85",
						"86", "87", "88", "89", "90", "91", "92", "93", "94",
						"95", "96", "97", "98", "99" });

		entityWheelView = new EntityWheelView(null,
				this.getString(R.string.guide_ageme),
				this.getString(R.string.guide_ageunit), true,
				Const.GUIDSEXCHOICEPARAMSIZE, Const.GUIDSEXCHOICEPARAMUNITSIZE,
				arrayWheelAdapter);
		mCustomScrovieView.startMyTration(entityWheelView);
	}

	private void setListener() {
		initNextLastBtnListener();
		layBack.setOnClickListener(this);
		mCustomScrovieView
				.setOnWeelChangeListener(mCustomScrovieView.new WeelChangeListener() {

					@Override
					public void onWeelChangeListener(CustomWheelView wheel,
							int oldValue, int newValue) {
						mAge = newValue;
					}
				});
	}

	private void initView() {
		mCustomScrovieView = (CustomScrovieView) mView
				.findViewById(R.id.guide_choiceage_whellview);
		initButton();
		initTopImgBtn();
		initToastTvBigSmall();

		setTextSmallBig(R.string.guide_ageis, R.string.guide_ageisornot);

	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		mView = inflater.inflate(R.layout.fragment_guide_choiceage, null);
		return mView;
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		super.onClick(v);

		switch (v.getId()) {
		case R.id.btn_guide_back:
			backDoJob(this);
			break;

		case R.id.btn_guide_next:
			nextDoJOb();
			break;

		case R.id.guide_linelayout_top_back:
			backDoJob(this);
			break;

		default:
			break;
		}
	}

	private void nextDoJOb() {

		EntityConversionTime conversionTime = Tools.getCurrentTimeEntity();
		mAge = conversionTime.getYearNUM() - mCustomScrovieView.getCurrentItem()-5 + 1;
		String tmString = mAge + "";
		mActivityGuide.getmEntityUserInfo().setBirthday(mAge + "-" + "01-01");
		Tools.startFragment(mActivityGuide,
				mActivityGuide.getmFragmentGudeRegister());
	}

}
